package com.huage.courseplatform.satoken.filter;

import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.stp.StpUtil;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class SaTokenWebMvcConfigurer implements WebMvcConfigurer {
    // 注册 Sa-Token 拦截器，打开注解式鉴权功能
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册 Sa-Token 拦截器，校验规则为 StpUtil.checkLogin() 登录校验。

        registry.addInterceptor(new SaInterceptor(handle -> StpUtil.checkLogin()))
                .addPathPatterns("/**")
                //放行路径
                .excludePathPatterns(
                        "/css/**",
                        "/druid/**",
                        "/static/img/**",
                        "/img/**",
                        "/temp/**",
                        "/login/**",
                        "/js/**",
                        "/index.html",
                        "**/doc.html",
                        "/doc.html/**",
                        "/doc.html",
                        "/webjars/**",
                        "/v2/**",
                        "/swagger-resources",
                        "/swagger-resources/**",
                        "/swagger-ui.html",
                        "/swagger-ui.html/**",
                        "/favicon.ico",
                        "/upload/imgById/**",
                        "/upload/videoById/**",
                        "/file/img/**",
                        "/file/video/**",
                        "/img/**",
                        "/video/**",
                        "/1lUvEEO5ck.txt"
                );
    }
}
